package cn.edu.zut.cs.Business;

import cn.edu.zut.cs.DAO.StudentDAO;
import cn.edu.zut.cs.Model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentService {
    StudentDAO studentDAO;

    @Autowired
    public void setStudentDAO(StudentDAO studentDAO) {
        this.studentDAO = studentDAO;
    }
    public double avechangeG() {
        double ave=0;
        int sum=0;
        List<Student> studentList = this.studentDAO.queryAll();
        System.out.println("成绩等级:");
        for (Student student : studentList) {
            sum += student.getGrade();
            if (student.getGrade()>=90 && student.getGrade()<=100)
                System.out.println(student.getName() + "  A");
            else if (student.getGrade() >= 80 && student.getGrade() <= 89)
                System.out.println(student.getName() + "  B");
            else if (student.getGrade() >= 70 && student.getGrade() <= 79)
                System.out.println(student.getName() + "  C");
            else if (student.getGrade() >= 60 && student.getGrade() <=69)
                System.out.println(student.getName() + "  D");
            else if (student.getGrade() < 60)
                System.out.println(student.getName() + "  E");
        }
        ave=(double) sum / studentList.size();
        return ave;

    }

}
